package com.cx.controller.lq;

import com.cx.constant.ConstantData;
import com.cx.pojo.Evaluate;
import com.cx.pojo.User;
import com.cx.service.lq.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("evaluate")
public class EvaluateController {

    @Autowired
    EvaluateService evaluateService;

    @RequestMapping("show")
    @ResponseBody
    public List<Evaluate> showEvaluate(int gameId){
        List<Evaluate> evaluates = evaluateService.selectAll(gameId);
        return evaluates;
    }

    @RequestMapping("add")
    @ResponseBody
    public String addEvaluate(HttpSession session,int gameId,String evaluateContent,int evaluateLevel){
        User user = (User) session.getAttribute(ConstantData.SESSION_KEY);
        int userId= user.getUserId();
        int affect = evaluateService.addEvaluate(gameId,userId,evaluateLevel,evaluateContent);
        if (affect>0)
            return "success";
        else
            return "fail";
    }

}
